package fr.nts.framework.core.commun.tool;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * MEthode utilitaire pour récupérer le context spring
 * 
 * @author sco
 * @version 1.0.0
 */
public class ApplicationContextHelper implements ApplicationContextAware{

	/**
	 * Contexte spring
	 */
	private static ApplicationContext applicationContext;
	
	
	/**
	 * @return Retourne le bean spring
	 */
	public static Object getBean(final String name){
		if(applicationContext != null){
			return applicationContext.getBean(name);
		}
		
		return null;
	}
	
	
	/**
	 * @return Récupère une instance du context spring
	 */
	public static ApplicationContext getApplicationContext(){
		return applicationContext;
	}


	/*
	 * (non-Javadoc)
	 * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
	 */
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException{
		ApplicationContextHelper.applicationContext = applicationContext;
	}
}